 <template>
 	<view class="page">
 		<view class="live-camera">
 			<view class="preview">
 				<image :src="resultUrl?resultUrl:path" mode="widthFix"></image>
 			</view>

 			<view class="bottom">
 				<template v-if="!resultUrl&&!path">
 					<view class="cancle" @click="cancle">
 						<!-- <image src="@/static/images/close_icon_1.png" mode="widthFix"></image> -->
 					</view>
 					<view class="save" @click="save">
 						<!-- <image src="@/static/images/save_icon.png" mode="widthFix"></image> -->
 					</view>
 				</template>

 				<template v-else>
 					<navigator :url="`/package_shibie/dataList/dataList?type=${type}`" hover-class="none" class="link">历史识别</navigator>
 					<view class="link" @click="cancle">继续拍照</view>
 				</template>

 			</view>
 		</view>
 	</view>
 </template>

 <script>
	import { HTTP_OLD_HOST, WEB_HOST, appid, appsecret } from '@/config.js'
	import { dateFormat, uploadImage, uploadToServe, } from '@/common/util.js'
 	export default {
 		data() {
 			return {
 				userInfo: uni.getStorageSync('userInfo'),
 				token: uni.getStorageSync('token'),
 				appid: appid,
 				appsecret: appsecret,
 				path: '',
 				systemInfo: {},
 				resultUrl: '',
 				type: ''
 			};
 		},
 		async onLoad(params) {
 			this.path = params.path;
 			this.type = params?.type || 1;
			this.save();
 		},
 		async onShow() {},
 		methods: {

 			// 获取手机系统信息
 			async getSystemInfo() {
 				//处理安卓手机异步授权问题 
 				let res = await getSystemInfo();
 				return res
 			},


 			save: async function() {
 				// 上传现场照片
 				let _this = this;
 				uni.showLoading({
 					mask: true,
 					title: '图片识别中'
 				})

 				uploadToServe({
 					type: 1,
 					url: 'https://wxapi.agri120.org/user/sb-insert.do',
 					filePath: this.path,
 					name: 'myfile',
 					formData: {
 						appid: _this.appid,
 						token: _this.token,
 						uid: _this.userInfo.uid,
 						type: _this.type
 					}
 				}).then((up_res) => {
 					console.log('up_res', up_res);
 					uni.hideLoading();
 					if (up_res.ret == 1000) {
 						uni.navigateTo({
 							url: `/package_shibie/dataList/dataList?type=${type}`
 						})
 					}
 				})
 			},


 			cancle: function() {
 				uni.redirectTo({
 					url: '/package_shibie/camera/camera?type=' + this.type
 				})
 			},

 			// save:function(){
 			// 	console.log(123)
 			// 	uni.navigateBack({
 			// 		delta:1
 			// 	})
 			// },

 		}
 	};
 </script>
 <style lang="scss">
 	.page {
 		height: 100%;
 	}

 	.live-camera {
 		height: 100%;

 		.preview {
 			display: flex;
 			justify-content: center;
 			align-items: center;
 			position: relative;
 			z-index: 1;
 			width: 100%;
 			height: calc(100% - 90px);

 			image {
 				width: 100%;
 			}
 		}

 		#cutImage {
 			position: absolute;
 			left: 0;
 			top: 0;
 			width: 100%;
 			height: 100%;
 			background: #f00;
 		}

 		.bottom {
 			position: absolute;
 			left: 0;
 			bottom: 0;
 			width: 80%;
 			padding: 0 10%;
 			height: 90px;
 			z-index: 98;
 			display: flex;
 			align-items: center;
 			justify-content: space-between;
 			background-color: #000;
 			box-sizing: inherit;

 			.cancle,
 			.save {
 				width: 90rpx;
 				height: 90rpx;
 				display: flex;
 				align-items: center;
 				justify-content: center;
 			}

 			.cancle {
 				color: #fff;
 				font-size: 34rpx;

 				image {
 					width: 50%;
 				}
 			}

 			.link {
 				color: #fff;
 				font-size: 34rpx;
 			}

 			.save {
 				image {
 					width: 60%;
 				}
 			}
 		}
 	}
 </style>